package com.ymtms.statisticalform.controller;

import com.ymtms.statisticalform.dao.GoodsbillMasterMapper;
import com.ymtms.statisticalform.pojo.CollectingMoneyBalance;
import com.ymtms.statisticalform.pojo.GoodsbillMaster;
import com.ymtms.statisticalform.pojo.MoneyFreight;
import com.ymtms.statisticalform.service.MoneyFreightService;
import com.ymtms.statisticalform.util.TimeRangeUtil;
import com.ymtms.statisticalform.util.ValidateUtil;
import com.ymtms.statisticalform.vo.GridRequest;
import com.ymtms.statisticalform.vo.GridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/freightrank")
public class FreightRankController {
    @Autowired
    private MoneyFreightService moneyFreightService;

    @RequestMapping("/test")
    @ResponseBody
    public Map test(String test){
        Map map = new HashMap();
        System.out.println("test");
        map.put("test","test");
        return map;
    }

    /**
     * 查询各种费用
     * 图表使用
     * @return
     */
    @RequestMapping("/moneyfreight")
    @ResponseBody
    public Map moneyFreight(String year,String month){
        Map map = new HashMap();

        List<MoneyFreight> moneyFreights = moneyFreightService.selectAllCarriageRanking(year,month);
        System.out.println(moneyFreights);
        map.put("moneyFreight",moneyFreights);
        return map;
    }

    /**
     * layui表格
     * @param gridRequest
     * @param year
     * @param month
     * @return
     */
    @RequestMapping("/moneyfreightlay")
    @ResponseBody
    public GridResult<MoneyFreight> moneyFreightLay(GridRequest gridRequest, /* 封装页面中laiyu表格所传过来的基本信息*/
                                                       String year,String month){
        System.out.println("gridRequest:"+gridRequest);
        System.out.println("DateString:"+year+",month:"+month);
        GridResult<MoneyFreight> result = moneyFreightService.moneyFreightLay(
                gridRequest, year,month);
//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(Integer.parseInt(params.get("page")), Integer.parseInt(params.get("limit")));
//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(1,10);
        result.setCode(0);
        result.setMsg("");
        System.out.println("数据："+result);
        return result;
    }

    /**
     * 营业收入查询
     * @return
     */
    @RequestMapping("/businessincome-chart")
    @ResponseBody
    public Map businessIncome(String year,String month){
        System.out.println("年:"+year+"-"+"月："+month);
        Map map = new HashMap();
        List<GoodsbillMaster> goodsbillMaster=moneyFreightService.selectBusinessIncomeByMonth(year,month);
        System.out.println(goodsbillMaster);
        map.put("businessIncomes",goodsbillMaster);
        return map;
    }
    @RequestMapping("/businessincome-table")
    @ResponseBody
    public GridResult<GoodsbillMaster> cmblist(GridRequest gridRequest, /* 封装页面中laiyu表格所传过来的基本信息*/
                                               String factDealDateString, /*实体类接收非范围参数*/
                                                      @RequestParam(value = "balanceDate", required = false) String balanceDate){
        String beginTime = "";
        String endTime = "";
        if (ValidateUtil.isNotEmpty(balanceDate)) {
            String[] split = balanceDate.split(" - ");
            beginTime = split[0];
            endTime = split[1];
        }
        System.out.println("gridRequest:"+gridRequest);
        System.out.println("factDealDateString:"+factDealDateString);
        System.out.println("balanceDate:"+balanceDate);
        GridResult<GoodsbillMaster> result = moneyFreightService.queryByPage(
                gridRequest, factDealDateString, new TimeRangeUtil(beginTime, endTime));
//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(Integer.parseInt(params.get("page")), Integer.parseInt(params.get("limit")));
//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(1,10);
        result.setCode(0);
        result.setMsg("");
        System.out.println("数据："+result);
        return result;
    }

}
